package util.grepkey;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by huashao on 16/8/2.
 */
public class SHAUtil {
    private  SHAUtil(){}

    public static MessageDigest getDigest(){
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            return messageDigest;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static String shaHex(String data){

        return shaHex(data.getBytes());
    }

    public static String shaHex(byte[] data){

        return HexUtil.toHexString(getDigest().digest(data));
    }


}
